package cn.lg.soar.common.util.jackson.deserializer;

import cn.lg.soar.common.util.DatetimeUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.util.Date;

/**
 * LocalTime 反序列化
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class SDateDeserializer extends JsonDeserializer<Date> {

    private final String pattern;

    public SDateDeserializer() {
        this.pattern = DatetimeUtil.PATTERN;
    }

    public SDateDeserializer(String pattern) {
        this.pattern = pattern;
    }

    @Override
    public Date deserialize(JsonParser parser, DeserializationContext context) throws IOException {
        return DatetimeUtil.toDate(parser.getText(), pattern);
    }

}
